Skip to content

id(search): memoize subject_kind resolution in search_terms — at most once per subject (#3013) - #3678

Closed
dezren39 wants to merge 1 commit into
mainfrom
queue/5518-3013-search-memoize
Closed

dezren39 wants to merge 1 commit into
mainfrom
queue/5518-3013-search-memoize

Conversation

@dezren39

@dezren39 dezren39 commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Fixes #3013. Queue task 5518 (routed by triage task 4363, CONFIRMED on main).

What

search_terms in pkgs/id/src/search.rs documented its subject_kind lookup as "called at most once per subject", but the per-term loop re-filtered every subject through the lookup for each SubjectKind term — N subjects × K kind terms = N×K calls (store reads for an uncached lookup), including for duplicate kind terms.

This resolves kinds lazily into a per-call cache (RefCell<HashMap<[u8;32], Option<String>>>) consulted before calling subject_kind, so the lookup runs at most once per distinct subject across the whole call. AND semantics, hit selection, and ordering are unchanged.

Test

New counting-lookup integration test in pkgs/id/tests/search.rs (test_search_terms_resolves_subject_kind_at_most_once_per_subject): 3 subjects (kinds alpha / beta / none) —

  • 2 identical kind terms: returns the alpha subject with its claims, lookup calls ≤ 3 (was 6 unmemoized)
  • 3 kind terms (two distinct + a duplicate): empty AND result, lookup calls ≤ 3

Targeted run: cargo test --test search search_terms on the laptop (results in the queue-task completion note; laptop under heavy fleet load this shift).

Scope exclusions per packet: no change to search_store_terms caller-side behaviour (#2779 separate), no search-semantics change.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

search_terms documented subject_kind as called at most once per subject,
but its per-term loop re-filtered every subject through the lookup for
each SubjectKind term (N subjects x K kind terms = N*K calls). Resolve
kinds lazily into a per-call cache so the lookup runs at most once per
distinct subject, including for duplicate kind terms. AND results are
unchanged.

Adds a counting-lookup integration test: 3 subjects x 2 identical kind
terms and x 3 kind terms (two distinct + a duplicate) each assert
<= 3 lookup calls with results identical to single-term behaviour.

Fixes #3013
@dezren39
dezren39 requested a review from a team as a code owner November 1, 2026 12:34
@coderabbitai

coderabbitai Bot commented Nov 1, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 61e02943-523f-41cc-bbec-dc2f9e5acc46
Commits

Reviewing files that changed from the base of the PR and between 4ae8da5 and 3453e65.

Files selected for processing: 2
  • pkgs/id/src/search.rs
  • pkgs/id/tests/search.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T12:36:10.313542Z 3453e65 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dezren39

dezren39 commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

Closing as superseded — not merged.

This PR and PR #3688 are the same work: queue task 5518 for issue #3013 (memoize subject_kind resolution in search_terms, at most once per subject), diffed against the identical base blob of pkgs/id/src/search.rs. PR #3688 merged on 2026-11-02 (merge commit 54cbdaf9ce520f65a4c7dd2d2b3a2c108b6962cc) and its implementation is the one on current main; issue #3013 is closed. This PR's branch now conflicts with main and its test would collide with the merged test of the same name.

Before closing, this PR was diffed in full against the canonical PR per the duplicate-PR protocol, and the salvage note is posted on PR #3688 (#3688 (comment)): the implementation has nothing unique (a RefCell wrapper around the same memo), and its two test scenarios — duplicate kind terms in one call, and a distinct kind term adding no new lookups — are covered by the merged test (3 kind terms incl. a duplicate, exactly 3 lookups, plus the single-term result check).

Disposition tracked by issue #6608 (pr-shepherd, Lane W fallback mode).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

queue/queued Has a queued queue task

Projects

None yet

1 participant